package com.kygeng.springframework.aop.framework.adapter;

import com.kygeng.springframework.aop.MethodAfterAdvice;
import com.kygeng.springframework.aop.MethodBeforeAdvice;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * @Title: MethodBeforeAdviceInterceptor
 * @Author: kygeng
 * @Package: com.kygeng.springframework.aop.framework.adapter
 * @Date: 2024/8/11 11:05
 * @Description: 方法拦截器
 */
public class MethodAfterAdviceInterceptor implements MethodInterceptor {

    private MethodAfterAdvice advice;

    public MethodAfterAdviceInterceptor() {
    }

    public MethodAfterAdviceInterceptor(MethodAfterAdvice advice) {
        this.advice = advice;
    }

    @Override
    public Object invoke(MethodInvocation methodInvocation) throws Throwable {
        this.advice.after(methodInvocation.getMethod(), methodInvocation.getArguments(), methodInvocation.getThis());
        return methodInvocation.proceed();
    }

}